// 预定相关接口服务
import { post, get } from '../../utils/request';

// 创建预定
const createBooking = (bookingData) => {
    return post('/home/prebook/create', bookingData)
        .then(res => {
            if (res.code === 200) {
                return res.data;
            } else {
                throw new Error(res.message || '预定失败');
            }
        });
};

// 获取预定列表
const getBookingList = (params = {}) => {
    return get('/home/prebook/list', params)
        .then(res => {
            if (res.code === 200) {
                return res.data;
            } else {
                throw new Error(res.message || '获取预定列表失败');
            }
        });
};

// 取消预定
const cancelBooking = (bookingId) => {
    return post('/home/prebook/cancel', { id: bookingId })
        .then(res => {
            if (res.code === 200) {
                return res.data;
            } else {
                throw new Error(res.message || '取消预定失败');
            }
        });
};

// 获取预定详情
const getBookingDetail = (bookingId) => {
    return get('/home/prebook/detail', { id: bookingId })
        .then(res => {
            if (res.code === 200) {
                return res.data;
            } else {
                throw new Error(res.message || '获取预定详情失败');
            }
        });
};

module.exports = {
    createBooking,
    getBookingList,
    cancelBooking,
    getBookingDetail
};